package com.sixmac.controller;

import com.sixmac.annotation.AuthUser;
import com.sixmac.common.base.BaseController;
import com.sixmac.core.plugins.dao.Blade;
import com.sixmac.core.toolbox.ajax.AjaxResult;
import com.sixmac.module.Installer;
import com.sixmac.module.Landlord;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by admin on 2018/9/4.
 */
@RequestMapping("/mine")
@ResponseBody
@Controller
public class MineController extends BaseController {


    /**
     * @api {post} /mine/index 0.1个人中心(信息已完善)
     * @apiName mine.index
     * @apiGroup mine
     * @apiParam {String} token token
     * @apiSuccess {String} user.code 111表示用户第一次登陆，需要创建用户 调用接口03
     * @apiSuccess {String} user.id 房东id
     * @apiSuccess {String} user.token token
     * @apiSuccess {String} user.name 房东名称
     * @apiSuccess {String} user.mobile 手机号码
     * @apiSuccess {String} user.sex 性别 1男2女
     * @apiSuccess {String} user.birthday 出生日期
     * @apiSuccess {String} user.region 区域
     * @apiSuccess {String} user.contract 合同照片
     * @apiSuccess {String} user.idCard 身份证号码
     * @apiSuccess {String} user.businessLicense 经营许可证
     * @apiSuccess {String} user.idCardFront 身份证正面
     * @apiSuccess {String} user.idCardReverse 身份证反面
     */
    @AuthUser
    @RequestMapping("/index")
    public AjaxResult index(Landlord landlord) {
        landlord = Blade.create(Landlord.class).findById(landlord.getId());
        return json(getData("landlord", landlord));

    }

    @AuthUser
    @RequestMapping("/logout")
    public AjaxResult logout(Landlord landlord) {
        Installer installer = Blade.create(Installer.class).findFirstBy("wechatKey='"+landlord.getWechatKey()+"'", null);
        if (installer!=null){
            installer.setWechatKey("");
            Blade.create(Installer.class).updateEveryCol(installer);
        }
        landlord = Blade.create(Landlord.class).findById(landlord.getId());
        landlord.setWechatKey("");
        Blade.create(Landlord.class).updateEveryCol(landlord);
        return success("退出成功");
    }
}
